package com.cg.design.graphicdesignpattern.builder;

/**
 * 使用Builder编写文档的类
 *
 * @program: LeetCode->Director
 * @description: 使用Builder编写文档的类
 * @author: cg
 * @create: 2022-03-20 20:58
 **/
public class Director {

    private Builder builder;

    public Director(Builder builder) {
        // 因为接收的参数是Builder类的子类，所有可以将其保存在builder字段中
        this.builder = builder;
    }

    /**
     * 编写文档的方法
     */
    public void construct() {
        // 标题
        builder.makeTitle("Greeting");
        // 字符串
        builder.makeString(" 从早上至晚上 ");
        // 条目
        builder.makeItems(new String[]{
                "早上好",
                "下午好。"
        });
        builder.makeString(" 晚上 ");
        builder.makeItems(new String[]{
                "晚上好。","晚安。","再见。"
        });
        // 完成，关闭
        builder.close();
    }

}
